import { defineStore } from "pinia";

const useUserInfoStore = defineStore("userInfo", {
  state: () => ({
      info: {} as any,
      token: ""
  }),
  getters: {
    getUserInfo:(state) => state.info,
    isLogin: (state) => Object.keys(state.info).length > 0,
    getToken: (state) => state.token,
  },
  actions: {
    updateUserInfo(userInfo: any) {
      this.info = userInfo;
    },
    setToken(token: string) {
      this.token = token;
    },
    logout() {
      this.info = {};
      this.token = "";
    },
  },
  persist: true,
});

export default useUserInfoStore;